package com.jh3502.vivo.function.message;

import android.support.annotation.NonNull;

import com.jh3502.vivo.base.BaseCallback;
import com.jh3502.vivo.base.BaseJson;
import com.jh3502.vivo.base.BasePresenter;
import com.jh3502.vivo.base.BaseView;
import com.jh3502.vivo.utils.Utils;

import java.util.List;
import java.util.Map;

/**
 * @author harisucici
 * @date 2017/6/19
 */

public class MessagePresenter extends BasePresenter<MessagePresenter.MessageView> {
    MessageModel mMessageModel;

    MessageView mMessageView;


    public void setMessageView(MessageView mMessageView) {
        this.mMessageView = mMessageView;

    }

    public void toFindMsg() {
        mMessageView.showLoadingDialog();
        if (mMessageModel == null) {
            mMessageModel = new MessageModel(mMessageView.getActContext());
        }

        mMessageModel.findMsg(new BaseCallback(mMessageView) {
            @Override
            public void responseSuccess(@NonNull BaseJson baseJson) {
                mMessageView.findMsgSuccess(Utils.getInstance().jsa2list(baseJson.getObj().toString()));
            }
        });
    }

    public void toDeleteMsg(Map<String, Object> body) {
        mMessageView.showLoadingDialog();
        if (mMessageModel == null) {
            mMessageModel = new MessageModel(mMessageView.getActContext());
        }

        mMessageModel.deleteMsg(body, new BaseCallback(mMessageView) {
            @Override
            public void responseSuccess(@NonNull BaseJson baseJson) {
                mMessageView.deleteMsgSuccess();
            }
        });
    }


    @Override
    public void cancelCall() {

    }

    public interface MessageView extends BaseView {
        void findMsgSuccess(List<Map<String, Object>> maps);

        void deleteMsgSuccess();
    }
}
